{include file="public/head"/}
<div class="container-fluid">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="alert alert-dismissable alert-info">
                <button type="button" class="close">×</button>
                <p></p>
            </div>
        </div>
    </div>
    <div class="ntDesktop">
        <div class="ntDesktop-head">{:lang("port_(warehouse)_list")}</div>
        <div class="col-md-12 column text-right">
            <div>
                <a href="/admin/logistics/portadd" class='btn btn-primary' data-toggle="modal"
                   data-target="#port_editModal"
                   stytle="margin-right:20px"> <span class="glyphicon glyphicon-plus"></span> {:lang("add_new_port(warehouse)")}</a>
            </div>
        </div>


        <div class="row clearfix">
            <div class="col-md-12 column">
                <table class="table table-striped table-hover ntTable" v-cloak>
                    <thead>
                    <tr>
                        <th> {:lang('country')}</th>
                        <th> {:lang('name')}</th>
                        <th> {:lang('type')}</th>
                        <th class="sorting" @click="sortfun(1)" data-order="1"> {:lang('edit')}</th>
                        <th> {:lang('operate')}</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr v-for="item in list" :key="item.id" v-if="list.length>0">
                        <td> {{item.countryname}}</td>
                        <td> {{item.name}}</td>
                        <td> {{item.typename}}</td>
                        <td> {{item.updatename}} <br/>
                            <small>{{item.update_date}}</small>
                        </td>
                        <td class="text-right">
                            <div>
                                <a v-if="item.type==2" href="#" class='btn btn-sm btn-info'><span class="fa fa-search-plus"></span>{:lang('details')}</a>
                                <a :href="'/admin/logistics/portedit?id='+item.id"
                                   class='btn btn-sm btn-primary' data-toggle="modal"
                                   data-target="#port_editModal" onfocus="this.blur()"><span
                                        class="glyphicon glyphicon-pencil"></span>{:lang('edit')}</a>
                                <a href="javascript:;" @click.prevent="delport(item.id)"
                                   class='btn btn-sm btn-default option-del'><span
                                        class="glyphicon glyphicon-trash"></span>{:lang('delete')}</a>
                            </div>
                        </td>
                    </tr>
                    <tr style="text-align: center;" v-if="list.length==0">
                        <td colspan="4">{:lang('no_data')}</td>
                    </tr>
                    </tbody>
                </table>
                <ul class="pagination" id="pagination">
                </ul>
            </div>
        </div>
    </div>
</div>
<!--添加弹窗部分 开始-->
<div class="modal fade" id="port_editModal" tabindex="-1" role="dialog" aria-labelledby="ntModalLabel"
     aria-hidden="true" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:1000px">

        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<!--弹窗部分 结束-->
{include file="public/foot"/}
<script>
    var table = new Vue({
        el: '.ntDesktop',
        data: {
            list: [],
            page: 1,
            pageSize: 2,
            order: 1,
            pauname: '',
        },
        methods: {
            setPage(pageCurrent, pageSum) {
                //数据总条数
                var myPageCount = pageSum;
                //一页显示多少条
                var myPageSize = this.pageSize;
                //总页数
                var countindex = myPageCount % myPageSize > 0 ? (myPageCount / myPageSize) + 1 : (myPageCount / myPageSize);
                $.jqPaginator('#pagination', {
                    totalPages: parseInt(countindex),
                    //最多显示多少页
                    visiblePages: 5,
                    //默认显示第几页
                    currentPage: pageCurrent,
                    first: '<li class="first"><a href="javascript:;">'+langcon.page_home+'</a></li>',
                    prev: '<li class="prev"><a href="javascript:;"><i class="arrow arrow2"></i>'+langcon.previous_page+'</a></li>',
                    next: '<li class="next"><a href="javascript:;">'+langcon.next_page+'<i class="arrow arrow3"></i></a></li>',
                    last: '<li class="last"><a href="javascript:;">'+langcon.last_page+'</a></li>',
                    page: '<li class="page"><a href="javascript:;">{{page}}</a></li>',
                    all:'<li class="page"><a href="javascript:;">'+parseInt(countindex)+' / '+this.page+'PG , '+this.pageSize+' /PG</a></li>',
                    onPageChange: (num, type) => {
                        if (type == "change") {
                            this.page = num
                            this.getAllList()
                        }
                    }
                });
            },
            //数据所有获取
            getAllList(){
                $.ajax({
                    url: "/admin/logistics/port",
                    type: 'post',
                    data: {
                        page: this.page,//分页
                        pageSize: this.pageSize,//条数
                    },
                    dataType: "json",
                    success: (result) => {
                        this.list = result.getports;
                        if (result.size / this.pageSize > 1) {
                            $('#pagination').show()
                            this.setPage(parseInt(this.page), result.size)
                        } else {
                            $('#pagination').hide()
                        }
                    }
                })
            },
            sortfun(type, $event){  //排序
                this.order = $(event.target).attr('data-order')
                if (type == 1) {
                    this.pauname = 'update_at'
                    this.list.sort(this.sortoneData);
                }
            },
            sortoneData(a, b) {
                if (this.order == 1) {
                    $(event.target).attr('data-order', 2)
                    return b.update_at - a.update_at
                } else {
                    $(event.target).attr('data-order', 1)
                    return a.update_at - b.update_at
                }
            },
            delport(id){
                $.ajax({
                    url: '/admin/logistics/portdel?id=' + id,
                    type: 'post',
                    success: (res) => {
                        res = JSON.parse(res)
                        change_mes_type('.alert',res.status)
                        if (res.status != 1) {
                            $('.alert').show()
                            $('.alert p').html('*' + res.msg + '<br>')
                        } else {
                            $('.alert').show()
                            $('.alert p').html('*' + res.msg + '<br>')
                            if (!(this.list.length - 1)) {
                                if(this.page>1){
                                    this.page--
                                }
                            }
                            this.getAllList()
                        }
                    }
                })
            },
        },
        created(){
            this.getAllList()
            $('#port_editModal').on('hide.bs.modal', () => {
                this.getAllList()
            })
        }
    })
    //替换之前的模板
    $("#port_editModal").on("hidden.bs.modal", function () {
        $(this).removeData("bs.modal");
        $(document).unbind('keydown')
    });
</script>
